//
//  RootViewController.m
//  Text_ problem
//
//  Created by jiboxue on 13-1-7.
//  Copyright (c) 2013年 jiboxue. All rights reserved.
//
//背景照片的key
#define bgImageKey @"bgImageKey"
//小对勾照片fram的key
#define okImageFramKey @"okImageFramKey"
//大对勾照片fram的key
#define bigOkImageFramKey @"bigOkImageFramKey"
//花的key
#define flowerImageKey @"flowerImageKey"
//桌上相框里面image的key
#define PhotoAlbumImage @"PhotoAlbumImage"

#import "RootViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "SetViewController.h"
#import "LandingViewController.h"
#import "EnvelopeAnimationViewController.h"
#import "CustomerInformation.h"

#import "UIImageView+WebCache.h"


#import "PMAPI.h"
#import "ASIHTTPRequest.h"
#import "ASIFormDataRequest.h"
#import "json.h"

@interface RootViewController ()



@end

@implementation RootViewController
@synthesize background;
@synthesize button_shop;
@synthesize button_money;
@synthesize button_set;
@synthesize imageViewleftCorner;
//两个view
@synthesize landingVC = _landingVC;
//ipad用的相册
@synthesize popoverController;
//照片还有名字
@synthesize label_name;
//信封动画
@synthesize EnvelopeAnimationVC = _EnvelopeAnimationVC;

////解析的数据
//@synthesize str_avatar = _str_avatar;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(reRead:) name:USERDEFAULT_WRITEOK object:nil];
        
        self.imageView_back = [[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)]autorelease];
        image_clock = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)];
        image_eye = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)];
        image_light = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)];
        _image_background_ok = [[UIImageView alloc]initWithFrame: CGRectMake(122, 373, 27, 21)];
        image_flower = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)];
        image_photo = [[UIImageView alloc]initWithFrame:CGRectMake(212, 510, 100, 115)];
        
        imageView_table = [[UIImageView alloc]initWithFrame: CGRectMake(311, 242, 395, 224)];
        
        self.view_white = [[[UIView alloc]initWithFrame:CGRectMake(311, 242, 395, 224)]autorelease];
        self.imageView_InScreen = [[[UIImageView alloc]initWithFrame:CGRectMake(24, 39.5, 343, 165)]autorelease];
        self.label_InScreen_name = [[[UILabel alloc]initWithFrame:CGRectMake(210, -7, 180, 30)]autorelease];
        self.label_inScreen_hour = [[[UILabel alloc]initWithFrame:CGRectMake(225, 138, 30, 30)]autorelease];
        
        appD = [UIApplication sharedApplication].delegate;
        self.image_head = [[[UIImageView alloc]initWithFrame:CGRectMake(15, 12, 95, 95)]autorelease];
        
        imageView_table_message = [[UIImageView alloc]initWithFrame:CGRectMake(414.5, 299.5, 188, 118)];
        imageView_table_message1 = [[UIImageView alloc]initWithFrame:CGRectMake(158, -5, 40, 39)];
        self.labelImageMessageNumber = [[[UILabel alloc]initWithFrame:CGRectMake(15, 7, 10, 20)]autorelease];
        
        guang_img_view = [[[UIImageView alloc]initWithFrame:CGRectMake(408.5, 297.5, 201.5, 126.5)]autorelease];
        
        self.button_information = [UIButton buttonWithType:UIButtonTypeCustom];
        //设置
        self.setVC = [[[SetViewController alloc]init]autorelease];
        //信封动画
        self.view_message = [[[UIView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)]autorelease];
        _EnvelopeAnimationVC = [[EnvelopeAnimationViewController alloc]init];
        
        m_imagePicker = [[UIImagePickerController alloc] init];
        popover = [[UIPopoverController alloc] initWithContentViewController:m_imagePicker];
    }
    return self;
}
-(void)playSound:(NSString*)soundKey{
	
	NSString *path = [NSString stringWithFormat:@"%@%@",[[NSBundle mainBundle] resourcePath],soundKey];
    
	SystemSoundID soundID;
	
	NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
	
	AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
	
	AudioServicesPlaySystemSound(soundID);
	
}
- (void)showLandingViewController
{
    //    [_landingVC.view removeFromSuperview];
    _landingVC.view.frame = CGRectMake(0, 0, 1024, 768);
    _landingVC = [[LandingViewController alloc]init];
    [self.view addSubview:_landingVC.view];
}
- (void)addLandingViewController
{
    [self.view addSubview:_landingVC.view];
}
-(void)removeview
{
    [_landingVC.view removeFromSuperview];
    
}
- (void)closeAll
{
    _landingVC.imageView_landing.alpha = 0;
    _landingVC.imageView_wifi.alpha = 0;
    
}
- (void)showLandingWifi
{
    [_landingVC showInfo:@"please manually re-connect internet"];
    _landingVC.imageView_landing.alpha = 0;
    _landingVC.imageView_wifi.alpha = 1;
}
- (void)closeLandingWifi
{
    _landingVC.imageView_landing.alpha = 0;
    _landingVC.imageView_wifi.alpha = 0;
}
-(void)reRead:(NSNotification *)note{
    
    NSLog(@"进来感觉");
    
    NSDictionary *dictionary_message = [CustomerInformation userMessage];
    if (dictionary_message)
    {
        
        NSLog(@"解析出来的东西 传dic = %@",dictionary_message);
        NSLog(@"图片地址 = %@",[dictionary_message objectForKey:@"avatar"]);
        [self.image_head setImageWithURL:[NSURL URLWithString:[dictionary_message objectForKey:@"avatar"]]placeholderImage:[UIImage imageNamed:@"default_avatar"]];
        
//        NSURL *url = [NSURL URLWithString:[dictionary_message objectForKey:@"avatar"]];
//        NSData *data = [NSData dataWithContentsOfURL:url];
//        self.image_head.image = [UIImage imageWithData:data];
        
        
        //        _str_avatar = [dictionary_message objectForKey:@"avatar"];
        [self.setVC.imageViewHead setImageWithURL:[NSURL URLWithString:[dictionary_message objectForKey:@"avatar"]]placeholderImage:[UIImage imageNamed:@"default_avatar"]];
        self.str_nickname = [dictionary_message objectForKey:@"nickname"];
        NSLog(@"nickname = %@",self.str_nickname);
        label_name.text = self.str_nickname;
        
        NSString *userAssets = [dictionary_message objectForKey:@"assets"];
        NSLog(@"解析出来的userid = %@",userAssets);
        self.label_assets.text = userAssets;
        
    }
    
    NSString *username1 = [dictionary_message objectForKey:@"username"];
    NSLog(@"username = %@",username1);
    NSString *password1 = [dictionary_message objectForKey:@"password"];
    NSLog(@"password = %@",password1);
    self.str_realname = [dictionary_message objectForKey:@"realname"];
    NSLog(@"realname = %@",self.str_realname);
    ASIHTTPRequest *request_latest = [PMAPI requestlatestUsernsme:username1 andPassword:password1];
    [request_latest startSynchronous];
    
    NSError *error = [request_latest error];
    if (error) {
        //todo something network error
        return [self showInfo:@"Internet Failure"];
        return;
    }
    
    if ([request_latest responseStatusCode] != 200)
    {
        return [self showInfo:@"user name and password do not match"];
        //todo something error with service error
    }
    
    //then something is succeed
    NSDictionary *dictionary_latest = [[request_latest responseString] JSONValue];
    
    NSLog(@"得到的问题 ＝ %@",dictionary_latest);
    
    self.questionList = [dictionary_latest objectForKey:@"question_group_list"];
    
    NSLog(@"有几个问题 = %d",self.questionList.count);
    
    NSArray *question_group = [self.questionList lastObject];
    self.question1 = [question_group objectAtIndex:0];
    
    _EnvelopeAnimationVC.self.question_anwer1 = self.question1;
    
    self.question2 = [question_group objectAtIndex:1];
    
    _EnvelopeAnimationVC.self.question_anwer2 = self.question2;
    
    
    if (self.questionList.count  != 0) {
        NSLog(@"222222222222222222222222");
        self.str_latest_one = [self.question1 objectForKey:@"content_text"];
        NSLog(@"第一个问题 = %@",_str_latest_one);
        
        NSLog(@"名字图片一类 = %@",[[self.question1 objectForKey:@"content_user"] objectForKey:@"nickname"]);
        
        self.str_latest_two = [self.question2 objectForKey:@"content_text"];
        
        NSString *mp3Path = [[NSBundle mainBundle]pathForResource:@"letter_sound" ofType:@"mp3"];
        if ([[NSFileManager defaultManager]fileExistsAtPath:mp3Path])
        {
            NSURL *mp3URL = [[[NSURL alloc]initFileURLWithPath:mp3Path]autorelease];
            NSError *error=nil;
            self.audioPlayer = [[[AVAudioPlayer alloc]initWithContentsOfURL:mp3URL error:&error]autorelease];
            if (error != nil)
            {
                NSLog(@"error:%@",error);
            }
            else
            {
                self.audioPlayer.volume = 0.5;
                self.audioPlayer.numberOfLoops = 0;//循环播放,默认0,不循环
                [self.audioPlayer prepareToPlay];//准备波饭,缓冲数据
                self.audioPlayer.delegate = self;
                [self.audioPlayer play];
                //                self.audioPlayer = audioTemp;
            }
        }
        //有信息时候...
        guang_img_view.image = [UIImage imageNamed:@"shine.png"];
        guang_img_view.alpha = 1;
        imageView_table_message.image = [UIImage imageNamed:@"bg_00049.png"];
        imageView_table_message.alpha = 1;
        imageView_table_message1.image = [UIImage imageNamed:@"number.png"];
        imageView_table_message1.alpha = 1;
        
        self.labelImageMessageNumber.backgroundColor = [UIColor clearColor];
        self.labelImageMessageNumber.textColor = [UIColor whiteColor];
        self.labelImageMessageNumber.text = [NSString stringWithFormat:@"%d",self.questionList.count];
        self.labelImageMessageNumber.alpha = 1;
        
        
        //时间间隔
        //        NSTimeInterval timeInterval =0.5;
        //按钮闪烁定时器
        showTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(changeguang) userInfo:nil repeats:YES]retain];
        
        self.button_information.frame = CGRectMake(420, 308, 175, 110);
        self.button_information.alpha = 1;
        [self.button_information addTarget:self action:@selector(buttonInformation) forControlEvents:UIControlEventTouchUpInside];
    }
    else
    {
        self.labelImageMessageNumber.alpha = 0;
    }
    //消失
    [[self.view viewWithTag:100] removeFromSuperview];
}
-(void)showInfo:(NSString *)textMessage
{
    UIAlertView *alertView =
    [[UIAlertView alloc] initWithTitle:@"Alert"
                               message:textMessage
                              delegate:self
                     cancelButtonTitle:@"OK"
                     otherButtonTitles:nil];
    
    [alertView show];
    [alertView release];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    image_light.image = [UIImage imageNamed:@"light_00000.png"];
    [background addSubview:image_light];
    
    //桌面相册的图片
    NSData *imageData = [[NSUserDefaults standardUserDefaults] dataForKey:PhotoAlbumImage];
    if (imageData != nil)
    {
        NSLog(@"桌面相册里面有数据");
        image_photo.image =  [UIImage imageWithData:imageData];
    }
    else
    {
        NSLog(@"桌面相册里面没数据");
        image_photo.image = [UIImage imageNamed:@"dog.png"];
    }
    
    
    //这个叫照片倾斜  完美
    image_photo.transform =  CGAffineTransformMakeRotation(M_PI*(-30.0/360));
    [background addSubview:image_photo];
    
    imageView_table.image = [UIImage imageNamed:@"tabel_b.png"];
    [background addSubview:imageView_table];
    
    self.view_white.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.0];
    _view_white.alpha = 0;
    [background addSubview:self.view_white];
    
    
    [self.label_InScreen_name setShadowOffset:CGSizeMake(0, -1)];
    [self.label_InScreen_name setShadowColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0.5]];
    self.label_InScreen_name.textColor = [UIColor colorWithRed:52.0/255 green:52.0/255 blue:52.0/255 alpha:1];
    self.label_InScreen_name.backgroundColor = [UIColor clearColor];
    self.label_InScreen_name.text = @"qqqqqqq";
    [self.imageView_InScreen addSubview:self.label_InScreen_name];
    
    self.label_inScreen_score = [[[UILabel alloc]init]autorelease];
    CGPoint center_seal_china = CGPointMake(270, 80);
    [self.label_inScreen_score setShadowOffset:CGSizeMake(0, -1)];
    [self.label_inScreen_score setShadowColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0.5]];
    self.label_inScreen_score.text = @"1700";
    self.label_inScreen_score.adjustsFontSizeToFitWidth = YES;
    self.label_inScreen_score.backgroundColor = [UIColor clearColor];
    self.label_inScreen_score.textColor = [UIColor colorWithRed:52.0/255 green:52.0/255 blue:52.0/255 alpha:1];
    [self.label_inScreen_score setFont:[UIFont fontWithName:@"STHeiti-Light" size:25.0f]];
    [self.label_inScreen_score sizeToFit];
    self.label_inScreen_score.center = center_seal_china;
    [self.imageView_InScreen addSubview:self.label_inScreen_score];
    
    self.label_inScreen_hour.backgroundColor = [UIColor clearColor];
    self.label_inScreen_hour.textColor = [UIColor redColor];
    self.label_inScreen_hour.text = @"2222222222222222222222";
    [self.imageView_InScreen addSubview:self.label_inScreen_hour];
    
    
    self.imageView_InScreen.image = [UIImage imageNamed:@"result.png"];
    self.imageView_InScreen.alpha = 0;
    [self.view_white addSubview:self.imageView_InScreen];
    
    //    //有信息时候...
    [background addSubview:guang_img_view];
    [background addSubview:imageView_table_message];
    [imageView_table_message addSubview:imageView_table_message1];
    self.labelImageMessageNumber.alpha = 0;
    [imageView_table_message1 addSubview:self.labelImageMessageNumber];
    
    self.imageView_back.image = [UIImage imageNamed:@"somethinginside.png"];
    self.imageView_back.userInteractionEnabled = YES;
    background.userInteractionEnabled = YES;
    [background addSubview:self.imageView_back];
    
    //添加去相册取照片的按钮
    UIButton *button_photographic = [UIButton buttonWithType:UIButtonTypeCustom];
    button_photographic.frame = CGRectMake(220, 520, 82, 92);
    [button_photographic addTarget:self action:@selector(buttonPhotographic:) forControlEvents:UIControlEventTouchUpInside];
    [self.imageView_back addSubview:button_photographic];
    
    button_clock = [UIButton buttonWithType:UIButtonTypeCustom];
    button_clock.frame = CGRectMake(880, 560, 60, 90);
    [button_clock addTarget:self action:@selector(button_clock_image) forControlEvents:UIControlEventTouchUpInside];
    [self.imageView_back addSubview:button_clock];
    image_clock.image = [UIImage imageNamed:@"clock_00000.png"];
    [self.imageView_back addSubview:image_clock];
    
    button_eye = [UIButton buttonWithType:UIButtonTypeCustom];
    button_eye.frame = CGRectMake(730, 470, 72, 130);
    [button_eye addTarget:self action:@selector(button_eye_image) forControlEvents:UIControlEventTouchUpInside];
    [self.imageView_back addSubview:button_eye];
    image_eye.image = [UIImage imageNamed:@"eye_00000.png"];
    [self.imageView_back addSubview:image_eye];
    
    button_light_clockwise = [UIButton buttonWithType:UIButtonTypeCustom];
    button_light_clockwise.frame = CGRectMake(60, 310, 135, 345);
    [button_light_clockwise addTarget:self action:@selector(button_image_light_clocwise) forControlEvents:UIControlEventTouchUpInside];
    [self.imageView_back addSubview:button_light_clockwise];
    
    button_light_anticlockwise = [UIButton buttonWithType:UIButtonTypeCustom];
    button_light_anticlockwise.alpha = 0;
    button_light_anticlockwise.frame = CGRectMake(60, 460, 140, 200);
    [button_light_anticlockwise addTarget:self action:@selector(button_image_light_anticlocwise) forControlEvents:UIControlEventTouchUpInside];
    [self.imageView_back addSubview:button_light_anticlockwise];
    
    button_background_green = [UIButton buttonWithType:UIButtonTypeCustom];
    button_background_green.alpha = 0;
    [button_background_green addTarget:self action:@selector(image_background_green) forControlEvents:UIControlEventTouchUpInside];
    button_background_green.frame = CGRectMake(107, 351, 60, 63);
    [self.imageView_back addSubview:button_background_green];
    button_background_white = [UIButton buttonWithType:UIButtonTypeCustom];
    button_background_white.alpha = 0;
    [button_background_white addTarget:self action:@selector(image_background_white) forControlEvents:UIControlEventTouchUpInside];
    button_background_white.frame = CGRectMake(143, 285, 60, 63);
    [self.imageView_back addSubview:button_background_white];
    button_background_pink = [UIButton buttonWithType:UIButtonTypeCustom];
    button_background_pink.alpha = 0;
    [button_background_pink addTarget:self action:@selector(image_background_pink) forControlEvents:UIControlEventTouchUpInside];
    button_background_pink.frame = CGRectMake(185, 350, 60, 63);
    [self.imageView_back addSubview:button_background_pink];
    
    _image_background_ok.image = [UIImage imageNamed:@"duigou.png"];
    _image_background_ok.alpha = 0;
    [self.imageView_back addSubview:_image_background_ok];
    
    NSString* str_flower = [[NSUserDefaults standardUserDefaults]stringForKey:flowerImageKey];
    if (str_flower != nil)
    {
        image_flower.image = [UIImage imageNamed:str_flower];
    }
    else
    {
        image_flower.image = [UIImage imageNamed:@"001.png"];
    }
    
    [self.imageView_back addSubview:image_flower];
    UIButton *button_flower = [UIButton buttonWithType:UIButtonTypeCustom];
    [button_flower addTarget:self action:@selector(button_image_flower) forControlEvents:UIControlEventTouchUpInside];
    button_flower.frame = CGRectMake(800, 330, 96, 96);
    [self.imageView_back addSubview:button_flower];
    
    //信息按钮
    [self.imageView_back addSubview:self.button_information];
    
    //+++++++++++++++++++++++++++++++++++++++++++++++
    //doc加一个黑色的层
    view_money = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)];
    view_money.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
    view_money.alpha = 0;
    [self.imageView_back addSubview:view_money];
    UIImageView *imageViewRound = [[UIImageView alloc]initWithFrame:CGRectMake(223.5, 96.5, 577, 575)];
    imageViewRound.image = [UIImage imageNamed:@"圆底.png"];
    [view_money addSubview:imageViewRound];
    //////////////传过来的钱数
    UIImageView *imageViewRound_1 = [[UIImageView alloc]initWithFrame:CGRectMake(47, 46, 483, 483)];
    imageViewRound_1.image = [UIImage imageNamed:@"profile_balance.png"];
    
    self.label_assets = [[[UILabel alloc]initWithFrame:CGRectMake(255, 230, 80, 33)]autorelease];
    self.label_assets.text = @"1";
    [self.label_assets setBackgroundColor:[UIColor clearColor]];
    [self.label_assets setFont:[UIFont fontWithName:@"AmericanTypewriter" size:20.0f]];
    self.label_assets.textColor = [UIColor redColor];
    self.label_assets.adjustsFontSizeToFitWidth = YES;
    //    _label_assets.minimumFontSize = 20;
    [imageViewRound_1 addSubview:self.label_assets];
    
    [imageViewRound addSubview:imageViewRound_1];
    [imageViewRound_1 release];
    [imageViewRound release];
    //设置加黑曾
    view_set = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)];
    view_set.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
    view_set.alpha = 0;
    [self.imageView_back addSubview:view_set];
    //压下一个试图在图层上
    [view_set addSubview:self.setVC.view];
    
    //图片变圆
    [self.image_head.layer setCornerRadius:self.image_head.frame.size.width / 2];
    [self.image_head.layer setMasksToBounds:YES];
    [self.image_head.layer setBorderWidth:0];
    self.image_head.image = [UIImage imageNamed:@"tiandiapp-v2-2_03.png"];
    [imageViewleftCorner addSubview:self.image_head];
    
    UIImageView *imageView_round = [[UIImageView alloc]initWithFrame:CGRectMake(13, 10, 100, 100)];
    imageView_round.image = [UIImage imageNamed:@"avatar_background.png"];
    [imageViewleftCorner addSubview:imageView_round];
    [imageView_round release];
    
    //再次近的时候读取本地化存储
    NSString* str = [[NSUserDefaults standardUserDefaults]stringForKey:bgImageKey];
    NSLog(@"%@",str);
    if (str != nil)
    {
        if ([[NSUserDefaults standardUserDefaults] stringForKey:okImageFramKey] != nil)
        {
            NSLog(@"%@",[[NSUserDefaults standardUserDefaults] stringForKey:okImageFramKey]);
            NSLog(@"hkjhjkhk==%@",str);
            NSLog(@"%@",[[NSUserDefaults standardUserDefaults]stringForKey:bgImageKey]);
            background.image = [UIImage imageNamed:str];
            _image_background_ok.frame = CGRectFromString([[NSUserDefaults standardUserDefaults] stringForKey:okImageFramKey]);
            NSLog(@"有background");
        }
    }
    else
    {
        background.image = [UIImage imageNamed:@"bg_blue.png"];
        _image_background_ok.frame = CGRectMake(122, 373, 27, 21);
        NSLog(@"无background");
    }
    
    [self.view_message  addSubview:_EnvelopeAnimationVC.view];
    self.view_message .backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
    
    self.view_message .alpha = 0;
    [self.view addSubview:self.view_message ];
    
    
    self.imageView_message_overtime = [[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)]autorelease];
    self.imageView_message_overtime.image = [UIImage imageNamed:@"timeisout_00049.png"];
    self.imageView_message_overtime.alpha = 0;
    [self.view addSubview:self.imageView_message_overtime];
    
    
    self.viewLanding = [[[UIView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)]autorelease];
    UILabel *label_login = [[[UILabel alloc]initWithFrame:CGRectMake(485, 390, 150, 50)]autorelease];
    label_login.text = @"Sign in";
    label_login.textColor = [UIColor whiteColor];
    label_login.backgroundColor = [UIColor clearColor];
    [self.viewLanding addSubview:label_login];
    
    self.viewLanding.backgroundColor = [UIColor blackColor];
    self.viewLanding.alpha = 0.6;
    //加载完成后用
    self.viewLanding.tag = 100;
    //加载小火轮
    self.activity = [[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]autorelease];
    self.activity.frame = CGRectMake(0, 0, 30, 30);
    self.activity.center = self.viewLanding.center;
    [self.activity startAnimating];
    //加到页面上
    [self.viewLanding addSubview:self.activity];
    [self.view addSubview:self.viewLanding];
}
#pragma mark - nstimer的方法
//nstimer的方法
-(void)changeguang
{
    
    int alpha = 0;
    if (guang_img_view.alpha == 0) {
        alpha = 1;
    }
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    guang_img_view.alpha = alpha;
    [UIView commitAnimations];
}
-(void)timerinvalidate
{
    [showTimer invalidate];
}
#pragma mark - 有消息是西风动画的按钮
-(void)buttonInformation
{
    //关掉定时器
    [showTimer invalidate];
    imageView_table_message.alpha = 0;
    guang_img_view.alpha = 0;
    self.button_information.alpha = 0;
    
    
    NSDictionary *dictionaryUserInfo = [CustomerInformation userMessage];
    NSString *username1 = [dictionaryUserInfo objectForKey:@"username"];
    NSLog(@"username = %@",username1);
    NSString *password1 = [dictionaryUserInfo objectForKey:@"password"];
    NSLog(@"password = %@",password1);
    ASIFormDataRequest *request_effective = [PMAPI requestUsername:username1 andPassword:password1 andQuestion:self.question1 andQuestion:self.question2];
    [request_effective startSynchronous];
    
    NSLog(@"问题的有效性数值 = %d",request_effective.responseStatusCode);
    
    if (request_effective.responseStatusCode != 200)
    {
        
        soundFile = [NSString stringWithFormat:@"/timeout.mp3"];
        [self playSound: soundFile];
        
        NSLog(@"1");
        self.imageView_message_overtime.alpha = 1;
        
        [NSTimer scheduledTimerWithTimeInterval:2/46.0 target:self selector:@selector(AnimationImage1:) userInfo:nil repeats:YES];
    }
    else
    {

        NSLog(@"2");
        [self.audioPlayer stop];
        
        [NSObject cancelPreviousPerformRequestsWithTarget:self];
        [self InformationInitialization];
        [_EnvelopeAnimationVC timer];
        soundFile = [NSString stringWithFormat:@"/letter_open.mp3"];
        [self playSound: soundFile];
    }
}
-(void)InformationInitialization
{
    _EnvelopeAnimationVC.button_confirm.userInteractionEnabled = YES;
    
    _EnvelopeAnimationVC.imageView_message.alpha = 1;
    
    _EnvelopeAnimationVC.imageView_boby.alpha = 1;
    
    //    _imageView_image.alpha = 0;
    self.view_message .alpha = 1;
    _EnvelopeAnimationVC.view.frame = CGRectMake(0, 0, 1024, 768);
    _EnvelopeAnimationVC.view.alpha = 1;
    
    _EnvelopeAnimationVC.label_ask.text = self.str_latest_one;
    [_EnvelopeAnimationVC.label_ask setNumberOfLines:2];
    _EnvelopeAnimationVC.label_ask.alpha = 0;////
    
    _EnvelopeAnimationVC.label_answer.textColor = [UIColor colorWithRed:160.0/255 green:160.0/255 blue:160.0/255 alpha:1];
    [_EnvelopeAnimationVC.label_answer setShadowOffset:CGSizeMake(0, -1)];
    [_EnvelopeAnimationVC.label_answer setShadowColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0.5]];
    [_EnvelopeAnimationVC.label_answer setBackgroundColor:[UIColor clearColor]];
    _EnvelopeAnimationVC.label_answer.alpha = 0;////
    
    _EnvelopeAnimationVC.label_ask1.text = self.str_latest_two;
    [_EnvelopeAnimationVC.label_ask1 setNumberOfLines:2];
    _EnvelopeAnimationVC.label_ask1.alpha = 0;////
    
    _EnvelopeAnimationVC.label_answer1.textColor = [UIColor colorWithRed:160.0/255 green:160.0/255 blue:160.0/255 alpha:1];
    [_EnvelopeAnimationVC.label_answer1 setShadowOffset:CGSizeMake(0, -1)];
    [_EnvelopeAnimationVC.label_answer1 setShadowColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0.5]];
    [_EnvelopeAnimationVC.label_answer1 setBackgroundColor:[UIColor clearColor]];
    _EnvelopeAnimationVC.label_answer1.alpha = 0;////
    
    [_EnvelopeAnimationVC.imageView_Headimage.layer setCornerRadius:_EnvelopeAnimationVC.imageView_Headimage.frame.size.width / 2];
    [_EnvelopeAnimationVC.imageView_Headimage.layer setMasksToBounds:YES];
    [_EnvelopeAnimationVC.imageView_Headimage.layer setBorderWidth:0];
    
    _EnvelopeAnimationVC.imageView_Headimage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[[self.question1 objectForKey:@"content_user"] objectForKey:@"display_photo"]]]];
    
//    _EnvelopeAnimationVC.imageView_Headimage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://appstore.tiandienergy.com:8181/td_zerodesign/application/photo/jing.fei.JPG"]]];
    _EnvelopeAnimationVC.imageView_Headimage.alpha = 0;////
    //印章里面的东西
    CGPoint center_seal_china = CGPointMake(723, 660);
    _EnvelopeAnimationVC.label_seal_china.transform =  CGAffineTransformMakeRotation(M_PI*(-46.0/360));
    _EnvelopeAnimationVC.label_seal_china.text = [[CustomerInformation userMessage] objectForKey:@"realname"];
    _EnvelopeAnimationVC.label_seal_china.adjustsFontSizeToFitWidth = YES;
    _EnvelopeAnimationVC.label_seal_china.alpha = 0;
    _EnvelopeAnimationVC.label_seal_china.backgroundColor = [UIColor clearColor];
    _EnvelopeAnimationVC.label_seal_china.textColor = [UIColor colorWithRed:37.0/255 green:50.0/255 blue:120.0/255 alpha:1];
    [_EnvelopeAnimationVC.label_seal_china setFont:[UIFont fontWithName:@"STHeiti-Light" size:20.0f]];
    [_EnvelopeAnimationVC.label_seal_china sizeToFit];
    _EnvelopeAnimationVC.label_seal_china.center = center_seal_china;
    
    
    CGPoint center_seal_english = CGPointMake(730, 680);
    _EnvelopeAnimationVC.label_seal_english.transform =  CGAffineTransformMakeRotation(M_PI*(-46.0/360));
    _EnvelopeAnimationVC.label_seal_english.text = [[CustomerInformation userMessage] objectForKey:@"username"];
    _EnvelopeAnimationVC.label_seal_english.adjustsFontSizeToFitWidth = YES;
    _EnvelopeAnimationVC.label_seal_english.alpha = 0;
    _EnvelopeAnimationVC.label_seal_english.backgroundColor = [UIColor clearColor];
    _EnvelopeAnimationVC.label_seal_english.textColor = [UIColor colorWithRed:37.0/255 green:50.0/255 blue:120.0/255 alpha:1];
    [_EnvelopeAnimationVC.label_seal_english setFont:[UIFont fontWithName:@"ArialMT" size:20.0f]];
    [_EnvelopeAnimationVC.label_seal_english sizeToFit];
    _EnvelopeAnimationVC.label_seal_english.center = center_seal_english;
    
    //名字
    CGPoint center = CGPointMake(540, 265);
    _EnvelopeAnimationVC.label_name_china.text = [[self.question1 objectForKey:@"content_user"] objectForKey:@"realname"];
    
    //[_EnvelopeAnimationVC.label_name_china setFont:[UIFont fontWithName:@"STHeitiTC-Light" size:14.0f]];
    
    _EnvelopeAnimationVC.label_name_china.alpha = 0;
    
    //[_EnvelopeAnimationVC.label_name_china setShadowOffset:CGSizeMake(0, -1)];
    //[_EnvelopeAnimationVC.label_name_china setShadowColor:[UIColor whiteColor]];
    [_EnvelopeAnimationVC.label_name_china setBackgroundColor:[UIColor clearColor]];
    _EnvelopeAnimationVC.label_name_china.textColor = [UIColor colorWithRed:149.0/255 green:149.0/255 blue:149.0/255 alpha:1];
    
    _EnvelopeAnimationVC.label_name_english.frame = CGRectMake(640, 178, 100, 30);
    _EnvelopeAnimationVC.label_name_english.text = [[self.question1 objectForKey:@"content_user"] objectForKey:@"username"];
    [_EnvelopeAnimationVC.label_name_english setFont:[UIFont fontWithName:@"AmericanTypewriter" size:20.0f]];
    //以下2句话时关键
    //[_EnvelopeAnimationVC.label_name_english sizeToFit];
    
    _EnvelopeAnimationVC.label_name_english.alpha = 0;
    [_EnvelopeAnimationVC.label_name_english setShadowOffset:CGSizeMake(0, -1)];
    [_EnvelopeAnimationVC.label_name_english setShadowColor:[UIColor whiteColor]];
    [_EnvelopeAnimationVC.label_name_english setBackgroundColor:[UIColor clearColor]];
    _EnvelopeAnimationVC.label_name_english.textColor = [UIColor colorWithRed:149.0/255 green:149.0/255 blue:149.0/255 alpha:1];
    
    _EnvelopeAnimationVC.underLine.frame = CGRectMake(_EnvelopeAnimationVC.label_name_china.center.x-(_EnvelopeAnimationVC.label_name_china.bounds.size.width/2), 275, _EnvelopeAnimationVC.label_name_china.bounds.size.width+_EnvelopeAnimationVC.label_name_english.bounds.size.width, 2.5);
    
    _EnvelopeAnimationVC.underLine.alpha = 0;////
    
    [_EnvelopeAnimationVC.button_confirm setBackgroundImage:[UIImage imageNamed:@"btn_normal.png"] forState:UIControlStateNormal];
    _EnvelopeAnimationVC.isQuestion1Answered = NO;
    _EnvelopeAnimationVC.isQuestion2Answered = NO;
    
    _EnvelopeAnimationVC.button_confirm.alpha = 0;////
    
    for (UIButton* btn in _EnvelopeAnimationVC.stars) {
        [btn setBackgroundImage:[UIImage imageNamed:@"star_normal.png"] forState:UIControlStateNormal];
    }
    for (UIButton* btn1 in _EnvelopeAnimationVC.stars1) {
        [btn1 setBackgroundImage:[UIImage imageNamed:@"star_normal.png"] forState:UIControlStateNormal];
    }
    
    for ( UIButton* btnTemp in _EnvelopeAnimationVC.stars) {
         btnTemp.alpha = 0;
    }
    for ( UIButton* btnTemp1 in _EnvelopeAnimationVC.stars1) {
        btnTemp1.alpha = 0;
    }
    
//    self.view_message.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:3];
    self.view_message.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
    [UIView commitAnimations];
    
}
-(void)AnimationImage1:(NSTimer *)timer
{
    static int i = 49;
    if (i == 87) {
        [timer invalidate];
        i = 49;
        [NSObject cancelPreviousPerformRequestsWithTarget:self];
        
        [self performSelector:@selector(outTimer) withObject:self afterDelay:0];
        return;
    }
    NSString *imageName = [NSString stringWithFormat:@"timeisout_000%02d",i++];
    NSString *filePath = [[NSBundle mainBundle] pathForResource:imageName
                                                         ofType:@"png"];
    UIImage *imageData = [[UIImage alloc]initWithContentsOfFile:filePath];
    self.imageView_message_overtime.image = imageData;
    [imageData release];
    
}
-(void)outTimer
{
    NSMutableArray *ary_clock = [[[NSMutableArray alloc]init]autorelease];
    for (int i = 66 ; i < 87; i++){
        
        NSString *imageName = [[NSString alloc]initWithFormat:@"timeisout_000%02d.png",i];
        [ary_clock addObject:[UIImage imageNamed:imageName]];
        [imageName release];
    }
    self.imageView_message_overtime.animationImages = ary_clock;
    self.imageView_message_overtime.animationDuration = 1.5;
    self.imageView_message_overtime.animationRepeatCount = 2;
    [self.imageView_message_overtime startAnimating];
    
    [self performSelector:@selector(outTimer_out) withObject:self afterDelay:3];
    
}
-(void)outTimer_out
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    self.imageView_message_overtime.alpha = 0;
    [UIView commitAnimations];
    
}

#pragma mark - 主页上面的名字还有图片传过来的值
-(void)setTextField:(NSString *)textField
{
    self.label_name.text = textField;
}
#pragma mark - 拍照的功能
-(void)buttonPhotographic:(id)sender
{
    soundFile = [NSString stringWithFormat:@"/btn_big.mp3"];
	[self playSound: soundFile];
    NSLog(@"11");
    UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"Change Profile Photo" delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"Camera " otherButtonTitles:@"Photo Ablums", nil];
    
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
    
    [actionSheet showInView:self.view];
    [actionSheet release];
    
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        NSLog(@"11");
        
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
            [m_imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
            [m_imagePicker setDelegate:self];
            self.popoverController = popover;
            [self.popoverController presentPopoverFromRect:CGRectMake(880, 620, 50, 50) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
        }else
        {
            [self showInfo:@"Cameca disabled"];
        }
    }
    else if (buttonIndex == 1) {
        NSLog(@"22");
        if ([UIImagePickerController isSourceTypeAvailable:
             UIImagePickerControllerSourceTypePhotoLibrary]) {
            m_imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            m_imagePicker.allowsEditing = YES;
            m_imagePicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
            m_imagePicker.delegate = self;
            self.popoverController = popover;
            [self.popoverController presentPopoverFromRect:CGRectMake(880, 620, 50, 50) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
            NSLog(@"popover = %d",popover.retainCount);
            NSLog(@"m_imagePicker = %d",m_imagePicker.retainCount);
        }else {
            [self showInfo:@"photo ablum disabled"];
        }
    }
}
//把编辑后的图片拿到
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    if (picker.allowsEditing == YES)
    {
        image = [info objectForKey:@"UIImagePickerControllerEditedImage"];
    }
    image_photo.image = image;
    //如果scourcetype是相机,需要保存照片
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
    [self.popoverController dismissPopoverAnimated:YES];//关掉当前视图
    ////////////////
    picker = nil;////////
    ////////////////
    //有用
    //写在存的按钮里
    NSData *imageData = UIImageJPEGRepresentation(image_photo.image, 100);
    [[NSUserDefaults standardUserDefaults] setObject:imageData forKey:PhotoAlbumImage];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
}
///网上加
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    [self setModalInPopover:YES];
}

#pragma mark - 花颜色的更换
//花颜色的更换
-(void)button_image_flower
{
    soundFile = [NSString stringWithFormat:@"/btn_big.mp3"];
	[self playSound: soundFile];
    static int i = 1;
    if (i == 1)
    {
        image_flower.image = [UIImage imageNamed:@"002.png"];
        [[NSUserDefaults standardUserDefaults]setObject:@"002.png" forKey:flowerImageKey];
        [[NSUserDefaults standardUserDefaults] synchronize];
        i = 2;
    }
    else if (i == 2)
    {
        image_flower.image = [UIImage imageNamed:@"003.png"];
        [[NSUserDefaults standardUserDefaults]setObject:@"003.png" forKey:flowerImageKey];
        [[NSUserDefaults standardUserDefaults] synchronize];
        i = 3;
    }
    else if (i == 3)
    {
        image_flower.image = [UIImage imageNamed:@"004.png"];
        [[NSUserDefaults standardUserDefaults]setObject:@"004.png" forKey:flowerImageKey];
        [[NSUserDefaults standardUserDefaults] synchronize];
        i = 4;
    }
    else if (i == 4)
    {
        image_flower.image = [UIImage imageNamed:@"001.png"];
        [[NSUserDefaults standardUserDefaults]setObject:@"001.png" forKey:flowerImageKey];
        [[NSUserDefaults standardUserDefaults] synchronize];
        i = 1;
    }
}
#pragma mark - 灯的动画
//逆时针灯
-(void)button_image_light_anticlocwise
{
    
    [NSObject cancelPreviousPerformRequestsWithTarget:self];
    button_light_anticlockwise.alpha = 0;
    soundFile = [NSString stringWithFormat:@"/light_close.mp3"];
	[self playSound: soundFile];
    
    [NSTimer scheduledTimerWithTimeInterval:1.5/45.0 target:self selector:@selector(light_anticlockwise_AnimationImage:) userInfo:nil repeats:YES];
    
    button_background_green.alpha = 0;
    button_background_white.alpha = 0;
    button_background_pink.alpha = 0;
    _image_background_ok.alpha = 0;
    [self performSelector:@selector(button) withObject:nil afterDelay:1.5];
}
//灯顺时针一张张加载
-(void)light_anticlockwise_AnimationImage:(NSTimer *)timer
{
    static int i = 45;
    if (i == 0) {
        [timer invalidate];
        i = 45;
        return;
    }
    NSString *imageName = [NSString stringWithFormat:@"light_000%02d", i--];
    NSString *filePath = [[NSBundle mainBundle] pathForResource:imageName ofType:@"png"];
    UIImage *imageData = [[UIImage alloc]initWithContentsOfFile:filePath];
    image_light.image = imageData;
    [imageData release];
    
}

//叫控制逆时针循环的按钮延后显示
-(void)button
{
    button_light_clockwise.alpha = 1;
}
#pragma mark - 这里有问题待解决 定时器最开速度是50毫秒-100毫秒所以不能用定时器还要想别的办法 普通的加载由于照片多会出现第一次加载停顿
//顺时针灯
-(void)button_image_light_clocwise
{
    [NSObject cancelPreviousPerformRequestsWithTarget:self];
    button_light_clockwise.alpha = 0;
    soundFile = [NSString stringWithFormat:@"/light_open.mp3"];
	[self playSound: soundFile];
    
    [NSTimer scheduledTimerWithTimeInterval:1.5/45.0 target:self selector:@selector(light_clockwise_AnimationImage:) userInfo:nil repeats:YES];
    [self performSelector:@selector(button_after) withObject:nil afterDelay:1.5];
}
//灯顺时针一张张加载
-(void)light_clockwise_AnimationImage:(NSTimer *)timer
{
    static int i = 0;
    if (i == 45) {
        [timer invalidate];
        i = 0;
        return;
    }
    NSString *imageName = [NSString stringWithFormat:@"light_000%02d", i++];
    NSString *filePath = [[NSBundle mainBundle] pathForResource:imageName ofType:@"png"];
    UIImage *imageData = [[UIImage alloc]initWithContentsOfFile:filePath];
    image_light.image = imageData;
    [imageData release];
    
}
//叫后面的对勾灯显示
-(void)button_after
{
    button_light_anticlockwise.alpha = 1;
    _image_background_ok.alpha = 1;
    button_background_green.alpha = 1;
    button_background_white.alpha = 1;
    button_background_pink.alpha = 1;
}

#pragma mark - 换背景颜色
//换背景颜色
-(void)image_background_green
{
    soundFile = [NSString stringWithFormat:@"/btn_small.mp3"];
    [self playSound: soundFile];
    appD.rootVC.background.image = [UIImage imageNamed:@"bg_blue.png"];
    _image_background_ok.frame = CGRectMake(122, 373, 27, 21);
    
    self.setVC.imageView_hook.frame = CGRectMake(225, 130, 27, 21);
    //NSUserDefaults本地存储
    [[NSUserDefaults standardUserDefaults]setObject:@"bg_blue.png" forKey:bgImageKey];
    [[NSUserDefaults standardUserDefaults]setValue:NSStringFromCGRect(_image_background_ok.frame) forKey:okImageFramKey];
    [[NSUserDefaults standardUserDefaults]setValue:NSStringFromCGRect(self.setVC.imageView_hook.frame) forKey:bigOkImageFramKey];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
//换背景颜色
-(void)image_background_white
{
    soundFile = [NSString stringWithFormat:@"/btn_small.mp3"];
    [self playSound: soundFile];
    appD.rootVC.background.image = [UIImage imageNamed:@"bg_write.png"];
    _image_background_ok.frame = CGRectMake(163, 306, 27, 21);
    NSLog(@"222");
    self.setVC.imageView_hook.frame = CGRectMake(125, 310, 27, 21);
    //NSUserDefaults本地存储
    [[NSUserDefaults standardUserDefaults]setObject:@"bg_write.png" forKey:bgImageKey];
    [[NSUserDefaults standardUserDefaults]setValue:NSStringFromCGRect(_image_background_ok.frame) forKey:okImageFramKey];
    [[NSUserDefaults standardUserDefaults]setValue:NSStringFromCGRect(self.setVC.imageView_hook.frame) forKey:bigOkImageFramKey];
    
    [[NSUserDefaults standardUserDefaults] synchronize];
    
}
//换背景颜色
-(void)image_background_pink
{
    soundFile = [NSString stringWithFormat:@"/btn_small.mp3"];
    [self playSound: soundFile];
    appD.rootVC.background.image = [UIImage imageNamed:@"bg_red.png"];
    _image_background_ok.frame = CGRectMake(202, 370, 27, 21);
    NSLog(@"333");
    self.setVC.imageView_hook.frame = CGRectMake(335, 310, 27, 21);
    //NSUserDefaults本地存储
    [[NSUserDefaults standardUserDefaults]setObject:@"bg_red.png" forKey:bgImageKey];
    [[NSUserDefaults standardUserDefaults]setValue:NSStringFromCGRect(_image_background_ok.frame) forKey:okImageFramKey];
    [[NSUserDefaults standardUserDefaults]setValue:NSStringFromCGRect(self.setVC.imageView_hook.frame) forKey:bigOkImageFramKey];
    
    [[NSUserDefaults standardUserDefaults] synchronize];
}
#pragma mark - 眼睛动的动画
//眼睛动的动画
-(void)button_eye_image
{
    soundFile = [NSString stringWithFormat:@"/character_chick.mp3"];
	[self playSound: soundFile];
    
    button_eye.userInteractionEnabled = NO;
    [NSTimer scheduledTimerWithTimeInterval:1.1/29.0 target:self selector:@selector(eye_animation:) userInfo:nil repeats:YES];
}
-(void)eye_animation:(NSTimer *)timer
{
    static int i = 0;
    if (i == 30) {
        [timer invalidate];
        i = 0;
        button_eye.userInteractionEnabled = YES;
        return;
    }
    NSString *imageName = [NSString stringWithFormat:@"eye_000%02d", i++];
    NSString *filePath = [[NSBundle mainBundle] pathForResource:imageName ofType:@"png"];
    UIImage *imageData = [[UIImage alloc]initWithContentsOfFile:filePath];
    image_eye.image = imageData;
    [imageData release];
}

#pragma mark - 表动的动画
//表动的动画
-(void)button_clock_image
{
    button_clock.userInteractionEnabled = NO;
    soundFile = [NSString stringWithFormat:@"/clock.mp3"];
	[self playSound: soundFile];
    
    [NSTimer scheduledTimerWithTimeInterval:1.5/20.0 target:self selector:@selector(clock_animation:) userInfo:nil repeats:YES];
}
-(void)clock_animation:(NSTimer *)timer
{
    static int i = 0;
    if (i == 20) {
        [timer invalidate];
        i = 0;
        button_clock.userInteractionEnabled = YES;
        return;
    }
    NSString *imageName = [NSString stringWithFormat:@"clock_000%02d", i++];
    NSString *filePath = [[NSBundle mainBundle] pathForResource:imageName ofType:@"png"];
    UIImage *imageData = [[UIImage alloc]initWithContentsOfFile:filePath];
    image_clock.image = imageData;
    [imageData release];
}
- (void)viewDidUnload
{
    [self setBackground:nil];
    [self setButton_shop:nil];
    [self setButton_money:nil];
    [self setButton_set:nil];
    [self setImageViewleftCorner:nil];
    [self setLabel_name:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
//横屏显示
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

- (void)dealloc {
    self.str_latest_one = nil;
    self.str_latest_two = nil;
    self.str_latest_one_id = nil;
    self.str_latest_two_id = nil;
    self.str_question_list = nil;
    self.view_white = nil;
    self.imageView_InScreen = nil;
    
    self.questionList = nil;
    self.audioPlayer = nil;
    
    [popover release];
    [m_imagePicker release];
    
    [guang_img_view release];
    self.view_white = nil;
    
    [background release];
    self.imageView_back = nil;
    [button_shop release];
    [button_money release];
    [button_set release];
    [imageViewleftCorner release];
    self.setVC = nil;
    [_landingVC release];
    [popoverController release];
    self.image_head = nil;
    [label_name release];
    self.label_assets = nil;
    [_EnvelopeAnimationVC release];
    self.view_message = nil;
    self.imageView_message_overtime = nil;
    //    [_str_avatar release];
    self.str_nickname = nil;
    
    [super dealloc];
}
#pragma mark - 左上角按钮的切换方式
//左上角按钮的切换方式
- (IBAction)buttonPress:(id)sender {
    UIButton *btn = (UIButton *)sender;
    soundFile = [NSString stringWithFormat:@"/btn_big.mp3"];
    [self playSound: soundFile];
    
    switch (btn.tag)
    {
        case 10:
        {
            NSDictionary *dictionary_message = [CustomerInformation userMessage];
            
            if (dictionary_message) {
                NSString *userId = [dictionary_message objectForKey:@"id"];
                NSString *password = [dictionary_message objectForKey:@"password"];
                NSString *username = [dictionary_message objectForKey:@"username"];
                
                NSString *text = [NSString stringWithFormat:@"td.store://%@;%@;%@",
                                  userId, password, username];
                
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:text]];
            }
            
            NSLog(@"去商店");
            break;
        }
        case 20:
        {
            if (view_money.alpha == 0) {
                view_set.alpha = 0;
                view_money.alpha = 1;
                [button_money setBackgroundImage:[UIImage imageNamed:@"haver.png"] forState:UIControlStateNormal];
                [button_set setBackgroundImage:[UIImage imageNamed:@"setting_off.png"] forState:UIControlStateNormal];
                NSLog(@"看有多少钱");
            }
            else
            {
                view_set.alpha = 0;
                view_money.alpha = 0;
                [button_money setBackgroundImage:[UIImage imageNamed:@"nor.png"] forState:UIControlStateNormal];
            }
            break;
        }
        case 30:
        {
            if (view_set.alpha == 0)
            {
                view_money.alpha = 0;
                view_set.alpha = 1;
                self.setVC.delegate = self;
                [button_money setBackgroundImage:[UIImage imageNamed:@"nor.png"] forState:UIControlStateNormal];
                [button_set setBackgroundImage:[UIImage imageNamed:@"setting_on.png"] forState:UIControlStateNormal];
                NSLog(@"设置");
            }
            else
            {
                view_money.alpha = 0;
                view_set.alpha = 0;
                [button_set setBackgroundImage:[UIImage imageNamed:@"setting_off.png"] forState:UIControlStateNormal];
            }
            break;
        }
        default:
            break;
    }
}

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    if (view_set.alpha == 1) {
        if(toInterfaceOrientation==UIInterfaceOrientationLandscapeRight) {
            //up
            NSLog(@"right");
            NSLog(@"x=%f",appD.rootVC.view.frame.origin.x);
            if (rootVC_x == 20||rootVC_x == 0) {
                
            }
            else
            {
                appD.rootVC.view.frame = CGRectMake(210, appD.rootVC.view.frame.origin.y, appD.rootVC.view.frame.size.width, appD.rootVC.view.frame.size.height);
            }
        }
        if(toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft) {
            //down
            NSLog(@"left");
            NSLog(@"x=%f",appD.rootVC.view.frame.origin.x);
            if (rootVC_x == 0||rootVC_x == -20) {
                
            }
            else
            {
                appD.rootVC.view.frame = CGRectMake(-190, appD.rootVC.view.frame.origin.y, appD.rootVC.view.frame.size.width, appD.rootVC.view.frame.size.height);
            }
        }
    }
}
//视图旋转之前自动调用
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    rootVC_x = appD.rootVC.view.frame.origin.x;
}

@end
